package com.hjxr.sysadmin.zsj.service.impl;

import com.hjxr.framework.config.ServerConfig;
import com.hjxr.sysadmin.zsj.domain.Pagephoto;
import com.hjxr.sysadmin.zsj.mapper.PagephotoMapper;
import com.hjxr.sysadmin.zsj.service.IPagephotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 页面图片Service业务层处理
 *
 * @author ruoyi
 * @date 2021-03-09
 */
@Service
public class PagephotoServiceImpl implements IPagephotoService
{
    @Autowired
    private PagephotoMapper pagephotoMapper;

    @Autowired
    private ServerConfig serverConfig;

    /**
     * 查询页面图片
     *
     * @param id 页面图片ID
     * @return 页面图片
     */
    @Override
    public Pagephoto selectPagephotoById(Long id)
    {
        Pagephoto pagephoto = pagephotoMapper.selectPagephotoById(id);
        if (pagephoto != null && pagephoto.getAddres() != null) {
            pagephoto.setRealaddres(serverConfig.getUrl() + pagephoto.getAddres());
        }
        return pagephoto;
    }

    /**
     * 查询页面图片列表
     *
     * @param pagephoto 页面图片
     * @return 页面图片
     */
    @Override
    public List<Pagephoto> selectPagephotoList(Pagephoto pagephoto)
    {
        List<Pagephoto> list = pagephotoMapper.selectPagephotoList(pagephoto);
        for (Pagephoto pagephoto1 : list) {
            if (pagephoto1 != null && pagephoto1.getAddres() != null) {
                pagephoto1.setRealaddres(serverConfig.getUrl() + pagephoto1.getAddres());
            }
        }
        return list;
    }

    /**
     * 新增页面图片
     *
     * @param pagephoto 页面图片
     * @return 结果
     */
    @Override
    public int insertPagephoto(Pagephoto pagephoto)
    {
        pagephoto.setModifiedTime(new Date());
        return pagephotoMapper.insertPagephoto(pagephoto);
    }

    /**
     * 修改页面图片
     *
     * @param pagephoto 页面图片
     * @return 结果
     */
    @Override
    public int updatePagephoto(Pagephoto pagephoto)
    {
        pagephoto.setModifiedTime(new Date());
        return pagephotoMapper.updatePagephoto(pagephoto);
    }

    /**
     * 批量删除页面图片
     *
     * @param ids 需要删除的页面图片ID
     * @return 结果
     */
    @Override
    public int deletePagephotoByIds(Long[] ids)
    {
        return pagephotoMapper.deletePagephotoByIds(ids);
    }

    /**
     * 删除页面图片信息
     *
     * @param id 页面图片ID
     * @return 结果
     */
    @Override
    public int deletePagephotoById(Long id)
    {
        return pagephotoMapper.deletePagephotoById(id);
    }
}
